package com.yd.app.service.pc.gStyleService;

import com.yd.app.mapper.GoodTypeMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.GStyle;
import com.yd.domain.business.GType;
import com.yd.domain.business.GTypeOne;
import com.yd.domain.business.PinXing;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.GTypeOneParam;
import com.yd.domain.sys.DicEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zy
 * @Desc: 商品分类
 * @Date:  2018/4/28
 * @Param
 */
@Service
public class GTypeOneService extends BaseService {

    @Autowired
    GoodTypeMapper goodsTypeMapper;

    /**
     * @Author: zy
     * @Desc: 查询商品导航
     * @Date:  2018/4/28
     * @Param
     */
    public List<GTypeOne> getTypeOne() {
        List<GTypeOne> list=goodsTypeMapper.getTypeOne();
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 商品类型下级查询
     * @Date:  2018/4/28
     * @Param
     */
    @Transactional
    public GTypeOne getSecondType(String pId,String level) {
        GTypeOne gt=new GTypeOne();
        if(level.equals(DicEnum.TYPE_LEVEL.LEVEL_ONE)){//一级查询二级
            List<GType> list=getGtypeList(pId);
            if(list!=null){
                gt.setTypeList(list);
            }else{
                gt.setStyleList(goodsTypeMapper.getGStyleList(pId));
                gt.setHaveType(DicEnum.TYPE_CHILD.NO_SECOND);
            }
        }else{//二级查询三级
            gt.setStyleList(goodsTypeMapper.getGStyleList(pId));
        }
        return gt;
    }
    /**
     * @Author: zy
     * @Desc: 二级
     * @Date:  2018/4/28
     * @Param
     */
    private List<GType> getGtypeList(String pId){
        List<GType> list=goodsTypeMapper.getGTypeList(pId);
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 查询第三级
     * @Date:  2018/4/28
     * @Param
     */
    private List<GStyle> getStyleList(String pId){
        List<GStyle> l=goodsTypeMapper.getGStyleList(pId);
        return l;
    }
    /**
     * @Author: zy
     * @Desc: 新增
     * @Date:  2018/5/2
     * @Param
     */
    public void  addGTypeOne(GTypeOne gType){
        goodsTypeMapper.addGTypeOne(gType);
    }
    /**
     * @Author: zy
     * @Desc: 修改
     * @Date:  2018/5/2
     * @Param
     */
    public void updateGTypeOne(GTypeOne gType){
        goodsTypeMapper.updateTypeOne(gType);
    }
    /**
     * @Author: zy
     * @Desc: 删除
     * @Date:  2018/5/2
     * @Param
     */
    public void deleteGTypeOne(String id){
        goodsTypeMapper.deleteTypeOne(id);
    }
    /**
     * @Author: zy
     * @Desc: 分页查询
     * @Date:  2018/5/2
     * @Param
     */
    public PageModel getGTypeOneList(GTypeOneParam gTypeParam, int pageIndex, int pageSize){
        PageModel pm=new PageModel();
        List<GTypeOne> list=new ArrayList<>();
        list=goodsTypeMapper.searchGTypeOneList(gTypeParam,getStartRow(pageIndex,pageSize),pageSize);
        int count=0;
        if(pageIndex==1){
            //查询总条数
            count=goodsTypeMapper.searchGTypeOneCount(gTypeParam);
            pm.setCount(count);
        }
        pm.setList(list);
        return pm;
    }
    /**
     * @Author: zy
     * @Desc: 根据iD查询
     * @Date:  2018/5/2
     * @Param
     */
    public GTypeOne getById(String id) {
        GTypeOne gTypeOne=goodsTypeMapper.getById(id);
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 获取商品的二级三级属性
     * @Date:  2018/5/3
     * @Param
     */
    public GTypeOne getTypeAndStyle(String type, String gstyle) {
        GTypeOne gTypeOne = new GTypeOne();
        if(!type.equals(null)&&!type.equals("")){
            gTypeOne.setTypeList(goodsTypeMapper.getTypeList(type));
        }
        if(!gstyle.equals(null)&&!gstyle.equals("")){
            gTypeOne.setStyleList(goodsTypeMapper.getStyleList(gstyle));
        }
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 查询二级
     * @Date:  2018/5/18
     * @Param
     */
    public GTypeOne getTypeByGoodType(String type) {
        GTypeOne gTypeOne = new GTypeOne();
        if(!type.equals(null)&&!type.equals("")){
            gTypeOne.setTypeList(goodsTypeMapper.getTypeList(type));
        }
        return gTypeOne;
    }
    /**
     * @Author: zy
     * @Desc: 查询三级
     * @Date:  2018/5/18
     * @Param
     */
    public GTypeOne getStyleByGoodStyle(String gstyle) {
        GTypeOne gTypeOne = new GTypeOne();
        if(!gstyle.equals(null)&&!gstyle.equals("")){
            gTypeOne.setStyleList(goodsTypeMapper.getStyleList(gstyle));
        }
        return gTypeOne;
    }
    /********************************************产品品型增删改查**********************************************/
    /**
     * @Author: zy
     * @Desc:删除
     * @Date:  2018/5/9
     * @Param
     */
    public void deletePX(String id) {
        goodsTypeMapper.deletePX(id);
    }
    /**
     * @Author: zy
     * @Desc:修改
     * @Date:  2018/5/9
     * @Param
     */
    public void updatePX(PinXing pinXing) {
        goodsTypeMapper.updatePX(pinXing);
    }
    /**
     * @Author: zy
     * @Desc:添加
     * @Date:  2018/5/9
     * @Param
     */
    public void addPinXing(PinXing pinXing) {
        goodsTypeMapper.addPinXing(pinXing);
    }

    public List<GTypeOne> getListByIds(String ids) {
        List<GTypeOne>list=  goodsTypeMapper.getListByIds(ids);
        return list;
    }
}
